/*
 SGBin.m
 Date Created: March 10, 2010
 
 Authors: Karanvir Gill <viper1029@gmail.com>
          Frank Lau <flaua@sfu.ca>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import "SGBin.h"

@implementation SGBin
@synthesize acceptsItems;
@synthesize isHighlighted;

- (SGBin*)initWithType:(SGBinType*)binType xLocation:(float)xCoor yLocation:(float)yCoor{
	self = [super init];
	if( self ) {
		UIImage *tempImage = [UIImage imageNamed:binType.image];
		[self initWithFrame:CGRectMake(xCoor, yCoor, tempImage.size.width, tempImage.size.height)];
		[self setImage:tempImage];
		[tempImage release];
		self.userInteractionEnabled=YES;
		acceptsItems = [binType acceptsItems];
    isHighlighted=NO;
	}
	return self;
}


- (BOOL)itemAccepted:(SGRecyclableItem*)item{
	// Check every element in the array
	for(int i=0;i<acceptsItems.count;i++){
		if(item.uniqueName ==  [acceptsItems objectAtIndex:i]){
			return true;
		}
		
	}
	return false;
}

- (void)setIsHighlighted:(BOOL)newIsHighlighted {
  if(isHighlighted==newIsHighlighted) return; // Already there, nothing to do
  
  isHighlighted=newIsHighlighted;
  if(isHighlighted) {
    [UIView beginAnimations:@"highlightBin" context:nil];
    CGAffineTransform transform = CGAffineTransformMakeScale(1.05, 1.05);
    self.transform = transform;
    [UIView commitAnimations];
  } else {
    [UIView beginAnimations:@"dehighlightBin" context:nil];
    CGAffineTransform transform = CGAffineTransformMakeScale(1, 1);
    self.transform = transform;
    [UIView commitAnimations];    
  }
}


@end
